package com.luo.shop.controller.admin;

import com.luo.shop.pojo.Category;
import com.luo.shop.service.CategoryService;
import com.luo.shop.service.admin.CategoryAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("admin/category")
public class CategoryAdminController {
    @Autowired
    private CategoryAdminService categoryAdminService;

    /**
     * 删除分类信息
     * @param id
     * @return
     */
    @GetMapping("delete")
    @ResponseBody
    public String delete(Long id){
        Integer delete = categoryAdminService.delete(id);
        if (delete>0){
            return "ok";
        }
        return "error";
    }
    /**
     * 添加分类信息
     * @param category
     * @return
     */
    @PostMapping("save")
    @ResponseBody
    public String save(Category category){
        Integer delete = categoryAdminService.save(category);
        if (delete>0){
            return "ok";
        }
        return "error";
    }
    /**
     * 修改分类信息
     * @param category
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public String update(Category category){
        Integer delete = categoryAdminService.update(category);
        if (delete>0){
            return "ok";
        }
        return "error";
    }
}
